<?php
/**
 * | ---------------------------------------------------------------------------------------------------
 * | Author：johnxu <fsyzxz@163.com>.
 * | ---------------------------------------------------------------------------------------------------
 * | Home: https://www.johnxu.net.
 * | ---------------------------------------------------------------------------------------------------
 * | Data: 2019-03-17
 * | ---------------------------------------------------------------------------------------------------
 * | Desc:
 * | ---------------------------------------------------------------------------------------------------
 */

namespace app\admin\model;

use think\Model;

class Config extends Model
{
    protected $name = 'config';

    protected $json = [ 'value' ];

    /**
     * 获取配置文件的值
     *
     * @param string $key
     *
     * @return mixed
     */
    public static function getValue( string $key )
    {
        return parent::get( [ 'key' => $key ] );
    }

    /**
     * 设置配置文件的值
     *
     * @param string $key
     * @param array  $value
     *
     * @return bool
     */
    public static function setValue( string $key, array $value )
    {
        $config        = self::getValue( $key ) ?? new self();
        $config->value = $value;
        $config->key   = $key;

        return $config->save();
    }
}